<template>
  <div>
    <el-table :data="warehouseInfoList">
      <el-table-column prop="warName" label="仓库名"></el-table-column>
      <el-table-column prop="warehouseDetailsInfoList[0].shopInfo.shopName" label="商品名"></el-table-column>
      <el-table-column prop="warehouseDetailsInfoList[0].lockStock" label="锁定库存"></el-table-column>
      <el-table-column prop="warehouseDetailsInfoList[0].maxNum" label="最大存储量"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div v-if="scope.row.isDeposit==true">
            <el-button size="mini" type="primary" @click="config(scope.row.id)">放入到该仓库</el-button>
          </div>
          <div v-if="scope.row.isDeposit==false">
            <el-button size="mini" type="danger" disabled>仓库已满</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageno"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
    export default {
        name: "tabrkth_T1dialog",
        data(){
          return{
            id:null,
            warehouseInfoList: [],
            pageno: 1,
            pagesize: 5,
            total: 1
          }
        },
        methods:{
          getData(id){
            this.warehouseInfoList=[];
            this.id=id;
            let returnShopInfo={
              id:id
            };
            let params=new URLSearchParams();
            params.append("pageno", this.pageno);
            params.append("pagesize", this.pagesize);
            Object.keys(returnShopInfo).forEach(item=>{
              params.append(item,returnShopInfo[item]);
            })
            // 根据退货申请id，查询可以存放的仓库有哪些
            this.$axios.get("gatherInfo/salesReturnWarehouse.action",{params:params}).
            then((response)=> {   //异步调用成功执行
              //将查询到的数据存入对象数组中
              this.warehouseInfoList=response.data.records;
              this.total = response.data.originalData.length;
            }).catch(function (error) {//异步调用失败执行
              alert(error);
            });
          },
          config(warId){
            //调用异步，添加入库和入库详情数据
            let params=new URLSearchParams();
            params.append("id", this.id);//退货申请id
            params.append("warehouseId", warId);//仓库id
            this.$axios.get("gatherInfo/addGatherInfoandSalesReturn.action",{params:params})
              .then(res=>{
                if(res.data.x){
                  this.$message.success(res.data.msg);
                  //重新刷新数据
                  this.$parent.$parent.getData();
                  //关闭模态框
                  this.$parent.$parent.t1_Visible=false;
                }else {
                  this.$message.error(res.data.msg);
                }
              })
              .catch(err=>{
                this.$message.warning(err);
                alert(err);
              })
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getData(this.id);
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getData(this.id);
          }
        }
    }
</script>

<style scoped>

</style>
